<?php
require_once 'classdb.php';
    class tin extends db
    {
        function layroot($id=-1)
        {
            return $this->get_by_thutu_db('tin_root',$id,1);
        }
        function laytin_theloai($id_root=-1,$id=-1)
        {
            return $this->get_by_thutu_db("tin_theloai", $id, 1, "and (id_root='$id_root' or '$id_root'=-1)",'');
        }
        function laytin_loai($idtl=-1,$id=-1)
        {
            return $this->get_by_thutu_db("tin_loai", $id, 1, "and (idtl='$idtl' or '$idtl'=-1)",'');
        }
        function laytour($id_root=-1,$dk2='',$id=-1)
        {
            return $this->get_by_thutu_db("tin", $id, 1, "and (id_root='$id_root' or '$id_root'=-1)",$dk2);
        }
        function laytour_theloai($idtl=-1,$dk2='',$id=-1)
        {
            return $this->get_by_thutu_db("tin", $id, 1, "and (idtl='$idtl' or '$idtl'=-1)",$dk2);
        }
        function laytour_loai($idloai=-1,$dk2='',$id=-1)
        {
            return $this->get_by_thutu_db("tin", $id, 1, "and (idloai='$idloai' or '$idloai'=-1)",$dk2);
        }
        function laylienhetructuyen()
        {
            return $this->get_by_thutu_db("lienhe");
        }
        function laytintonghop($id=-1,$idgroup='')
        {
            return $this->get_by_thutu_db("tin_tonghop", $id, -1, "and (idgroup='$idgroup' or '$idgroup'='')","limit 0,6");
        }
        function laytintonghopphantrang($pageNum=1,$pageSize=9,&$totalRows,$id=-1,$idgroup='')
        {
            $totalRows = 0;
            $sql="select count(id) from tin_tonghop
             where anhien=1
             ORDER BY thutu asc";
            $kq = mysql_query($sql) or die (mysql_error());
            $row_kq = mysql_fetch_row($kq);
            $totalRows = $row_kq[0];

            $startRow = ($pageNum - 1)*$pageSize;

            $sql="select * from tin_tonghop
                 where anhien=1
                 ORDER BY thutu asc
                 LIMIT $startRow , $pageSize";
            $kq=mysql_query($sql) or die(mysql_error());
            //echo $sql; die;
            return $kq;
        }
        function laytintonghoplienquan($id,$idgroup='')
        {
             return $this->get_by_thutu_db("tin_tonghop", -1, 1, "and (idgroup='$idgroup' or '$idgroup'='') and (id between $id-3 and $id+3) and id<>$id","");
        }
        function layfield($idgroup='')
        {
            $sql="select * from field where idgroup='$idgroup' ";
            $kq=mysql_query($sql) or die(mysql_error());
            //echo $sql; die;
            return $kq;
        }
        function laythuvienanh()
        {
            return $this->get_by_thutu_db('thuvienanh');
        }

    }

?>
